package negocio.Modelo;
import integracion.Factoria.*;
import integracion.Marcas.DAOMarcas;
import integracion.Modelo.*;
import integracion.Vehiculo.*;

public class SAModeloImp implements SAModelo {
	

	@Override
	public boolean crearModelo(TransferModelo t) {
		 FactoriaDAO FacTdao = FactoriaDAO.getInstancia();
		 DAOModelo daoModelo = FacTdao.newDAOModelo();
		 DAOMarcas daoMarcas = FacTdao.newDAOMarcas();
		 if(daoMarcas.searchable(t.getMarca()))
		 if(daoModelo.creable(t) && daoMarcas.readById(t.getMarca())!=null)
			 return daoModelo.create(t);
		 return false;
	}

	@Override
	public boolean eliminarModelo(TransferModelo t) {
		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOModelo daoModelo = FactDao.newDAOModelo();
		DAOVehiculo daoVehiculo = FactDao.newDAOVehiculo();
		if(daoModelo.deletable(t) && !daoVehiculo.containsModelo(t.getId()))
			return daoModelo.delete(t);
		return false;
	}

	@Override
	public TransferModelo buscarModelo(int id) {
		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOModelo daoModelo = FactDao.newDAOModelo();
		if(daoModelo.searchable(id))
			return daoModelo.readById(id);
		return null;
		}

	@Override
	public boolean actualizarModelo(TransferModelo t) { 		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOModelo daoModelo = FactDao.newDAOModelo();
		DAOMarcas daoMarcas = FactDao.newDAOMarcas();
		if(daoMarcas.searchable(t.getMarca()))
		if(daoModelo.updatable(t))
			return daoModelo.update(t);
		return false;				
	}	
}
	
